const { defineConfig } = require('@vue/cli-service')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const isProduction = process.env.NODE_ENV === 'production'
module.exports = defineConfig({
  publicPath: isProduction ? './' : '/',

  outputDir: 'dist',

  assetsDir: 'static',

  lintOnSave: true,

  runtimeCompiler: true,

  transpileDependencies: [
    /* string or regex */
  ],

  productionSourceMap: true,
  chainWebpack: config => {
    // yarn
    if (process.env.USE_ANALYZER) {
      config
        .plugin('webpack-bundle-analyzer')
        .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
    }

    // gzip
    if (isProduction) {
      config
        .plugin('compression')
        .use(CompressionWebpackPlugin)
        .tap(args => {
          return [
            {
              test: /\.js$|\.html$|\.css/,
              threshold: 10240,
              deleteOriginalAssets: false
            }
          ]
        })
    }

    config.resolve.alias.set('async-validator', 'async-validator/lib/index.js')
  },
  configureWebpack: {
    devtool: 'source-map'
  },

  css: {
    extract: false,

    sourceMap: false,

    loaderOptions: {},
  },

  parallel: require('os').cpus().length > 1,
  pwa: {},
  pages: {
    index: {
      entry: 'src/main.js',
      template: 'public/index.html',
      filename: 'index.html',
      title: '唐山市燃气行业综合监管平台',
      buildTime: new Date().toString()
    }
  },

  // configure webpack-dev-server behavior
  devServer: {
    host: '0.0.0.0',
    port: 80,
    
    proxy: {

      '/geourl': {
        target: 'http://47.94.21.243:7779/',
        changeOrigin: true,
        pathRewrite: {
          '^/geourl': ''
        }
      },
      '/apis': {
        target: 'http://192.168.110.254:8069/', //254环境
        
        changeOrigin: true,
       // ws: true, // websocket
        pathRewrite: {
          '^/apis': ''
        }
      },

    },
  },

  pluginOptions: {}
})
